import Vue from 'vue'
import Vuex from 'vuex'

let openid = ''
let isReadPrivacy = 'N'
try {
  const value = uni.getStorageSync('openid')
  if (value) openid = value
  const _isReadPrivacy = uni.getStorageSync('isReadPrivacy')
  if (_isReadPrivacy) isReadPrivacy = _isReadPrivacy
} catch (e) {}

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    vx_openid: openid,
    isReadPrivacy,
  },
  mutations: {
    setOpenid: (state, data) => {
      state.vx_openid = data
      uni.setStorageSync('openid', data)
    },
    setReadStatus: (state, data) => {
      state.isReadPrivacy = data
      uni.setStorageSync('isReadPrivacy', data)
    },
  },
  getters: {
    isReadPrivacy: (state) => state.isReadPrivacy,
  },
})

export default store
